package action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import vo.ServiceResponse;
import vo.impl.InputValueObject;
import basic.action.BasicAction;

public class MemberAction extends BasicAction {
	/**
	 * Logger for this class
	 */
	private static final Logger LOGGER = Logger.getLogger(MemberAction.class);

	public ActionForward login(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		InputValueObject ivo = new InputValueObject();
		Map<String, String> params = new HashMap<String, String>();
		params.put("name", "hikelee");
		params.put("password", "123456");
		ivo.setParams(params);
		ServiceResponse sresponse=this.serviceProxy.doService(ivo, serviceId, "login");
		if(sresponse.getException()!=null){
			sresponse.getException().printStackTrace();
			return null;
		}
		return info(mapping, form, request, response);
	}

	public ActionForward info(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		List list = (List) this.serviceProxy.doService(null, serviceId, "info").getResult();
		request.setAttribute("list", list);
		return mapping.findForward("info");
	}

	public ActionForward setsess(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		String name = request.getParameter("name");
		String password = request.getParameter("password");
		request.getSession().setAttribute("name", name);
		request.getSession().setAttribute("password", password);
		return null;
	}
}